package com.example.petadoption.Service;

import com.example.petadoption.Entity.Pet;
import com.example.petadoption.Repository.PetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class PetService {

    @Autowired
    private PetRepository petRepository;

    public List<Pet> getAvailablePets() {
        return petRepository.findByIsAdoptedFalse();
    }

    public Pet addPet(Pet pet) {
        if (pet.getName() == null || pet.getName().trim().isEmpty()) {
            throw new IllegalArgumentException("宠物名称不能为空");
        }
        return petRepository.save(pet);
    }
}